﻿using System.Drawing;
using System.Windows.Forms;

namespace StockLib.Indicator
{
    public partial class StockMaIndicator : StockIndicator
    {
        public override void DrawGraphTitle(Graphics g, Rectangle rect, int index)
        {
            int y = (rect.Top + rect.Bottom) / 2;
            int x = rect.Left;

            float[] ma = CalcOutput(index);
            for (int i = 0; i < maDays.Count; i++)
            {
                Color color = StockProfile.IndicatorColors[i];
                string textOutput = string.Format("MA{0}:{1:#0.00}", maDays[i], ma[i]);
                TextRenderer.DrawText(g, textOutput, font, new Point(x, y), color, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                x += TextRenderer.MeasureText(textOutput, font).Width;
            }
        }

        public override void DrawGraphTitle(Graphics g, Rectangle rect)
        {
            this.DrawGraphTitle(g, rect, indexEnd);
        }

        public override void DrawGraphData(Graphics g)
        {
            for (int index = indexStart; index <= indexEnd; index++)
            {
                if (index <= 1)
                    continue;

                int xPos = GetXPos(index);
                int xPosLast = GetXPos(index - 1);

                float[] ma = CalcOutput(index);
                float[] maLast = CalcOutput(index - 1);
                for (int i = 0; i < maDays.Count; i++)
                {
                    if (index > maDays[i])
                    {
                        int yPos = GetYPos(ma[i]);
                        int yPosLast = GetYPos(maLast[i]);
                        g.DrawLine(StockProfile.IndicatorPens[i], xPosLast, yPosLast, xPos, yPos);
                    }
                }
            }
        }
    }
}
